package com.logic.modular.game.battle.process.skillEffectHandle.base;

import com.logic.modular.game.battle.panel.attribute.PlayerHeroAttributeServiceImpl;
import com.logic.modular.game.battle.panel.attribute.domain.EffectStatus;
import com.logic.modular.game.battle.panel.attribute.domain.PlayerHeroAttribute;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffect;
import com.logic.modular.game.battle.panel.skillEffect.domain.SkillEffectStatus;
import com.logic.modular.game.battle.panel.skillEffect.PvpSkillEffectServiceImpl;
import com.logic.modular.game.battle.info.FiledName;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 处理
 * 效果冲突
 */
@Slf4j
@Component
public class EffectHandle3 {
    public static final List<Integer> NON_NUMERICAL = new ArrayList<>(Arrays.asList(11, 21));
    @Resource
    private PvpSkillEffectServiceImpl pvpSkillEffectService;
    @Resource
    private PlayerHeroAttributeServiceImpl attributeService;

    /**
     * 冲突判定
     *
     * @param skillEffect 技能效果
     */
    public void trySkillEffectTypeConflict(PvpSkillEffect skillEffect) {
        if (skillEffect.getStatus().getStatus() == 0) {
            return;
        }
        String battleUUID = skillEffect.getBattleUUID();

        Long battleId = skillEffect.getBattleId();
        Long targetPlayerHeroId = skillEffect.getTargetPlayerHeroId();
        Long coreSkillEffectTypeId = skillEffect.getCoreSkillEffectTypeId();
        Integer coreSkillEffectTypeType = skillEffect.getCoreSkillEffectTypeType();
        SkillEffectStatus skillEffectStatus = skillEffect.getStatus();

        PlayerHeroAttribute targetAttribute
                = attributeService.get(battleUUID, targetPlayerHeroId);
        if (NON_NUMERICAL.contains(coreSkillEffectTypeType)) {//
            Map<Long, EffectStatus> targetAttributeStatus = targetAttribute.getStatus();
            if (targetAttributeStatus.containsKey(coreSkillEffectTypeId)){
                skillEffectStatus.setStatus(0);
                skillEffectStatus.failReasons.add(-3);
                FiledName.logSkillFailReason(-11);
            }else {
                skillEffectStatus.setStatus(7);
            }
            skillEffect.setStatus(skillEffectStatus);
        }
    }
}
